# 封装发送请求与提取响应数据的方法
import requests


class SendMethod():
    # 发送请求
    @staticmethod
    def sendmethod(method, url, params=None, body=None):
        if method == "get":
            resp = requests.get(url, params)
        elif method == "post":
            resp = requests.post(url, body)
        else:
            resp = None
            print("输入请求错误")

        # 提取响应数据
        result = {}
        if resp is not None:
            result['status_code'] = resp.status_code
            result['header'] = resp.headers
            result['body'] = resp.json()
            result["resp_time"] = int(resp.elapsed.microseconds / 1000)
            return result
        else:
            return resp


if __name__ == '__main__':
    url = 'http://127.0.0.1:8000/api/add_event/'
    payload = {
        'eid': 3494,
        'name': '黑米101发布会',
        'limit': 30,
        'status': 1,
        'address': '哪个教室',
        'start_time': '2022-7-30'
    }
